package com.cool4j.view

import org.eclipse.core.runtime.Platform
import org.eclipse.jface.resource.ImageDescriptor
import org.eclipse.ui.plugin.AbstractUIPlugin
import org.osgi.framework.BundleContext

/**
 * The activator class controls the plug-in life cycle
 *
 * @author Frank create on 16/1/8 11:20
 */
class Activator extends AbstractUIPlugin {

    /** The plug-in ID */
    static final def PLUGIN_ID = "CodeGenerator"

    /** The shared instance */
    private static Activator plugin

    /** Constructor */
    Activator() {}

    /**
     * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
     */
    @Override
    void start(BundleContext context) throws Exception {
        super.start(context)
        plugin = this
    }

    /**
     * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
     */
    @Override
    void stop(BundleContext context) throws Exception {
        plugin = null
        super.stop(context)
    }

    /**
     * Returns the shared instance.
     *
     * @return - the shared instance
     */
    static def getDefault() {
        return plugin
    }

    /**
     * Returns an image descriptor for the image file at the given plug-in relative path.
     *
     * @param path - the path
     * @return - the image descriptor
     */
    static ImageDescriptor getImageDescriptor(path) {
        return imageDescriptorFromPlugin(PLUGIN_ID, path)
    }

    /**
     * 获取代码生成器工作目录,如果目录不存在则创建目录
     *
     * @return
     */
    static def getDataFolder() {
        def workspacePath = Platform.getInstanceLocation().getURL().getPath()
        workspacePath.replace("\\", "/")
        def dataFolder = workspacePath + "codegenerator/"
        return dataFolder
    }

}
